<template>
  <j-modal
    :title="title"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="按周设置">
          <div style="width: 100%">
            <a-card v-for="(detail,detailIndex) in detailOptions" size="small" :style="{ marginTop: '5px' }">
              <a-form layout="inline" style="width: 100%;">
                <a-form-item
                  layout="inline">
                  <span class="ant-input-span"> {{ detail.week }}  </span>
                </a-form-item>
                <a-form-item
                  layout="inline">
                  <span class="ant-input-span">    权重：  </span>
                  <a-input-number v-model="detail.rate"/>
<!--                  <span class="ant-input-span">  %</span>-->
                </a-form-item>
<!--                <a-form-item
                  layout="inline">
                  <a href="#" v-if="detailOptions.length > 0" @click="handleDelDetailClick(detailIndex)">删除</a>
                </a-form-item>-->
              </a-form>
            </a-card>
          </div>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "StmKpiCalendarModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        detailOptions: [],
        weekList : ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          batchAdd: "/stm/stmKpiCalendar/batchAdd",
        },
      }
    },
    created () {
    },
    methods: {
      add (record) {
        this.detailOptions = [];
        this.form.resetFields();
        this.model = Object.assign({}, record);
        console.log(this.model)
        this.weekList.forEach(item => {
          this.detailOptions.push({ week: item, rate: '' })
        })
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let formData = Object.assign(this.model, values);
            formData.detailList = this.detailOptions;
            
            console.log(formData)
            httpAction(this.url.batchAdd,formData,'post').then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                that.close();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
.ant-input-span {
  white-space:pre;
}
</style>